package chapter9;

import java.util.Scanner;

public class CalculateNum {
    int baseNum;//基础数值
    int item;   //当前项的值
    int count;  //数值的次数
    long result;  //最后相加的结果

//    两个参数的构造方法
    public CalculateNum(int baseNum,int count){
        this.baseNum=baseNum;
        this.count=count;
        this.item=baseNum;
        this.result=baseNum;

    }

    //计算结果
    public  void getNumResult(){
        for (int i=1;i<count;i++){
            item=10*item+baseNum;
            result+=item;
        }
    }
    //打印结果
    public void showResult(){
        String info=""+baseNum;
        item=baseNum;
        for (int i=1;i<count;i++){
            item=10*item+baseNum;
            info=info+"+"+item;
        }
        info=info+"="+result;
        System.out.println(info);
    }

    public static void main(String[] args) {

        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入数值");
        int num=scanner.nextInt();
        System.out.println("请输入次数");

        int count=scanner.nextInt();

        CalculateNum ca=new CalculateNum(num,count);
        ca.getNumResult();
        ca.showResult();
    }



}
